//
//  BaseViewController.m
//  NewProject
//
//  Created by macbook on 2022/2/21.
//

#import "BaseViewController.h"

#ifdef RELEASE
#else
    /*app调试*/
//#import "FLEXManager.h"
#endif

@interface BaseViewController ()<UIGestureRecognizerDelegate>

@property (nonatomic, strong) UIView *backView;

@end

@implementation BaseViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    if (self.navigationController.viewControllers.count > 1) {
        self.tabBarController.tabBar.hidden = YES;
    }else {
        self.tabBarController.tabBar.hidden = NO;
    }
    self.navigationController.interactivePopGestureRecognizer.delegate = self;

    if (@available(iOS 13.0, *)) {
        self.overrideUserInterfaceStyle = UIUserInterfaceStyleLight;
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDarkContent;
    } else {
        // Fallback on earlier versions
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = ColorHex(@"#FFFFFF");
    
    _eventView = [[EventView alloc] initWithFrame:self.view.bounds];
    self.view = _eventView;
    
    [self createNav];

}

#pragma mark - CraeteUI
- (void)createNav {
    self.navView = [PesoKit createImageViewWithFrame:CGRectMake(0, 0, KScreenWidth, kStarBarHeight) imageNamed:@""];
    self.navView.backgroundColor = [UIColor whiteColor];
    self.navView.userInteractionEnabled = YES;
    [self.view addSubview:self.navView];
    
    self.backButton = [PesoKit createButtonWithFrame:CGRectMake(12, self.navView.height-13-20, 20, 20) backGroundColor:[UIColor clearColor] title:@"" titleColor:[UIColor clearColor] font:[UIFont systemFontOfSize:12]];
    [self.backButton setBackgroundImage:[UIImage imageNamed:@"ic_backBtn_white"] forState:0];
    [self.backButton addTarget:self action:@selector(backButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.navView addSubview:self.backButton];
    
    self.titleLabel = [PesoKit createLabelWithFrame:CGRectMake(50, kStarBarHeight-10-25, KScreenWidth-100, 25) backGroundColor:[UIColor clearColor] text:@"" textColor:ColorHex(@"#FFFFFF") font:FONT(FontWeightStyleMedium, 17)];
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    [self.navView addSubview:self.titleLabel];
    
    _backView = [PesoKit createViewWithFrame:CGRectMake(0, kStarBarHeight, KScreenWidth, KScreenHeight-kStarBarHeight) backGroundColor:ColorHex(@"#FFFFFF")];
    [self.view addSubview:_backView];
}

#pragma mark - SET&GET
- (void)setBackColor:(UIColor *)backColor {
    _backColor = backColor;
    _backView.backgroundColor = backColor;
}

#pragma mark - Action
- (void)backButtonClick:(UIButton *)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(navigationViewBackActionWithItem:)]) {
        [self.delegate navigationViewBackActionWithItem:self.backButton];
    } else {
        [[AppTools getCurrentVC].navigationController popViewControllerAnimated:YES];
    }
}

#pragma mark - Methods
/*让手势生效*/
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    if (self.navigationController.viewControllers.count <= 1) {
        return NO;
    }
  return YES;
}

/*允许同时响应多个手势*/
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
   return YES;
}
 
/*禁止响应手势的是否ViewController中scrollView跟着滚动*/
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return [gestureRecognizer isKindOfClass:UIScreenEdgePanGestureRecognizer.class];
}

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
#ifdef RELEASE
#else
    /*app调试*/
//    [[FLEXManager sharedManager] showExplorer];
#endif
}

@end
